home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / tkern10.zip / SRC\TKERN.C < prev    next >
Text File  |  1994-05-14  |  3KB  |  123 lines

  1. /*
  2.  *  This file forms part of "TKERN" - "Troy's Kernel for Windows".
  3.  *
  4.  *  Copyright (C) 1994  Troy Rollo <troy@cbme.unsw.EDU.AU>
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <windows.h>
  22. #include <toolhelp.h>
  23. #include <stdlib.h>
  24. #include <memory.h>
  25. #include <string.h>
  26. #include <alloc.h>
  27. #include <stdarg.h>
  28. #include <errno.h>
  29. #include <sys/tfile.h>
  30. #include <sys/task.h>
  31. #include <sys/ioctl.h>
  32. #include <sys/wait.h>
  33. #include <sys/tkern.h>
  34.  
  35. HWND    hwndManager = 0;
  36.  
  37. static    void task_is_dead(int    iTask);
  38.  
  39.  
  40. /* Note that at the end of this we execute the tkern file manager.
  41.  * this is a tkern executable which handles all access to all file
  42.  * type objects. It has to be done this way because files and windows
  43.  * and sockets etc are per task objects. Without doing this, we can't
  44.  * pass objects from a parent task to a child task.
  45.  */
  46.  
  47. #pragma argsused
  48. BOOL    CALLBACK _export
  49. LibMain(HINSTANCE hInstance,
  50.     WORD    wDataSeg,
  51.     WORD    cbHeapsize,
  52.     LPSTR    strCmdLine)
  53. {
  54.     files_init();
  55.     if (WinExec("tkfmangr", SW_HIDE) < 32)
  56.     {
  57.         files_cleanup();
  58.         return FALSE;
  59.     }
  60.     process_init();
  61.     return TRUE;
  62. }
  63.  
  64.  
  65.  
  66. int far _export
  67. tkern_register_manager(HWND hwndManager_)
  68. {
  69.     if (hwndManager)
  70.         return 0;
  71.     hwndManager = hwndManager_;
  72.     tkern_wakeup_call();
  73.     return 1;
  74. }
  75.  
  76.  
  77.  
  78. void    far _export
  79. tkern_wakeup_call(void)
  80. {
  81.     int    i, iTask;
  82.  
  83.     if (!nSleepers)
  84.         return;
  85.     for (i = 0; i < TNTASK; i++)
  86.     {
  87.         if (_tasks[i].nFlags & TF_ASLEEP)
  88.         {
  89.             for (iTask = i;
  90.                  _tasks[iTask].hTask == HTASK_FLEDGELING;
  91.                  iTask = _tasks[iTask].iParent);
  92.             PostAppMessage(_tasks[iTask].hTask, TKWM_WAKEUP, 0, 0);
  93.             _tasks[i].nFlags &= ~TF_ASLEEP;
  94.             nSleepers--;
  95.         }
  96.     }
  97. }
  98.  
  99. void    far _export
  100. tkern_kill_ok(void)
  101. {
  102.     if (!nTasks)
  103.     {
  104.         SendMessage(hwndManager, TKWM_ALLDONE, 0, 0);
  105.     }
  106. }
  107.  
  108. int    far _export
  109. tkern_errno(void)
  110. {
  111.     struct    task *pt;
  112.  
  113.     pt = GetTaskInfo();
  114.     return pt->nError;
  115. }
  116.  
  117. void    far _export
  118. tkern_seterrno(int nError_, int    iTask)
  119. {
  120.     _tasks[iTask].nError = nError_;
  121. }
  122.  
  123.